﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Threading;
using System.Windows.Forms;

namespace Xuat_Nhap_Excel
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void napdulieu()
        {
            DataTable table;
            if (dtgSinhVien.DataSource != null)
            {
                table = (DataTable)dtgSinhVien.DataSource;
            }
            else
            {
                table = new DataTable();
            }

            var inputParam = new List<InputParamExcel>
            {
                new InputParamExcel {Ten = "STT", ThuocTinh = InputTypeExcel.String},
                new InputParamExcel {Ten = "CT01", ThuocTinh = InputTypeExcel.String},
                new InputParamExcel {Ten = "CT02", ThuocTinh = InputTypeExcel.String},
                new InputParamExcel {Ten = "CT03", ThuocTinh = InputTypeExcel.String},
                new InputParamExcel {Ten = "CT04", ThuocTinh = InputTypeExcel.String},
                new InputParamExcel {Ten = "CT05", ThuocTinh = InputTypeExcel.String}
            };
            //inputParam.Add(new InputParamExcel { Ten = "STT", ThuocTinh = InputTypeExcel.String });

            var frm = new FrmSaoChep(inputParam);
            frm.ViTriHeader = 2;
            frm.ShowDialog();
            var checkclose = frm.Checkclose;
            if (checkclose) return;
            var b = FrmSaoChep.ResultValue;
            if (frm.RadioXoavathem)
            {
                dtgSinhVien.DataSource = b;
            }
            else
            {
                table.Merge(b);
                dtgSinhVien.DataSource = table;
            }
            FrmSaoChep.ResultValue = null;
            //_thread.Abort();
        }

        private void btnSaoChep_Click(object sender, EventArgs e)
        {
            napdulieu();
        }

        private void show()
        {
            _frmloading = new FrmLoading();
            _frmloading.Show();
        }
        private Thread _thread;
        private FrmLoading _frmloading;

        private void btnloadding_Click(object sender, EventArgs e)
        {
            _thread = new Thread(Method1);
            _thread.IsBackground = true;
            _thread.Start();
            _frmloading = new FrmLoading();
            _frmloading.ShowCancel(true);
            _frmloading.ShowDialog();
            
        }
        private void Method1()
        {
            Thread.Sleep(3000);
            MessageBox.Show("đã xong");
        }
    }
}
